package com.xiaotao.es.controller;

import com.xiaotao.es.common.R;
import com.xiaotao.es.domain.vo.DocumentVo;
import com.xiaotao.es.util.StringUtils;
import lombok.RequiredArgsConstructor;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xiaotao
 */
@RestController
@RequestMapping("es")
@RequiredArgsConstructor
public class EsController {
    private final RestHighLevelClient restHighLevelClient;

    @RequestMapping("page")
    public R<?> listByPage(Long size, Long currentPage, @RequestBody DocumentVo documentVo){
        BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
        if (StringUtils.isNotEmpty(documentVo.getContent())) {
            queryBuilder.must(QueryBuilders.termQuery("content",documentVo.getContent()));
        }
        //restHighLevelClient.search()
        return R.ok();
    }
}
